package edu.zju.gis.dbfg.model.base;

import org.locationtech.jts.geom.Geometry;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 包含了空间信息，属性信息
 * Created by ylj on 2017/9/27.
 */
public class GeoItem implements Cloneable, Serializable{
    private Geometry geometry;
    private Map<String,Object> prop;
    private String fid;
    public GeoItem(){}
    public GeoItem(Geometry geometry){
        this.geometry = geometry;
    }
    public GeoItem(Geometry geometry, Map<String, Object> prop){
        this.geometry = geometry;
        this.prop = prop;
    }
    public GeoItem(String fid, Geometry geometry, Map<String, Object> prop){
        this.fid = fid;
        this.geometry = geometry;
        this.prop = prop;
    }
    public Geometry getGeometry() {
        return geometry;
    }
    public void setGeometry(Geometry geometry) {
        this.geometry = geometry;
    }

    public Map<String, Object> getProp() {
        return prop;
    }

    public void setProp(Map<String, Object> prop) {
        this.prop = prop;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Geometry copyGeometry = (Geometry) geometry.clone();
        Map<String,Object> copyProp = new HashMap<>();
        for (Map.Entry<String,Object> entry : prop.entrySet()){
            copyProp.put(entry.getKey(),entry.getValue());
        }

        return new GeoItem(fid, copyGeometry,copyProp);
    }

    public String getFid() {
        return fid;
    }

    public void setFid(String fid) {
        this.fid = fid;
    }
}
